package com.cy.pj.sys.server.impl;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.annotation.RequiredTime;
import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.server.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @DATE: 2021/3/15 19:38
 * @Author: LuckyH
 */
@Service
@Slf4j
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao sysLogDao;

    @RequiredTime
    @RequiredLog(operation="公告查询")
    @Override
    public List<SysLog> selectLogs(SysLog sysLog) {

        long t1 = System.currentTimeMillis();
        log.info("method start {}",t1);
        System.out.println("log.find.thread->"+ Thread.currentThread().getName());
        List<SysLog> sysLogs = sysLogDao.selectLogs(sysLog);
        long t2 = System.currentTimeMillis();
        log.info("method end {}",t2);
        return sysLogs;
    }

    @RequiredTime
    @RequiredLog(operation = "Id查询")
    @Override
    public SysLog selectById(Long id) {
        SysLog sysLog = sysLogDao.selectById(id);
        return sysLog;
    }

    /**
     * Async 描述方法为一个异步切入点方法
     * @param sysLog
     * @return
     */
    @Async
    @Override
    public void insertLog(SysLog sysLog) {

        System.out.println("save.log.thread->"+ Thread.currentThread().getName());
        sysLogDao.insertLog(sysLog);
        //return rows;
    }

    // 事物回滚 事物切入点方法
    @Transactional
    @RequiredLog(operation = "删除日志")
    @Override
    public int deleteLogs(Long... ids) {
        int rows = sysLogDao.deleteLogs(ids);
        return rows;
    }
}
